﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

using LowLevelGraphics;
using LowLevelGraphics.Filter;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// Execute given filter type
    /// </summary>
    public class ActionExecuteFilterType : AbstractCommand
    {
        private Type m_FilterType = typeof(void);
        private object[] m_aParam = null;
        private Bitmap m_Bitmap = null;

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionExecuteFilterType"/> class.
        /// </summary>
        /// <param name="_type">The _type.</param>
        /// <param name="_bitmap">The _bitmap.</param>
        /// <param name="_aParam">The _a param.</param>
        public ActionExecuteFilterType(Type _type, Bitmap _bitmap, params object[] _aParam )
        {
            m_FilterType = _type;
            m_aParam = _aParam;
            m_Bitmap = _bitmap;
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            IFilter filter = (IFilter)Activator.CreateInstance(m_FilterType, m_aParam);
            UnsafeBitmap bitmap = filter.Execute(m_Bitmap);
            bitmap.Dispose();
        }
    }
}
